/**
 * Created by 小敏哥 on 2017/6/23.
 * 废弃了
 */
import React, {Component} from 'react'
import {connect} from 'react-redux'
import HandleProcess from '../../components/OrderDetails/handelProcess/handleProcess'
import DocumentList from '../../components/sendTheAddress/documentList';
import {getOrderDetail, getRequirements} from '../../actions/sendTheAddressOfOverLineAction';
import AlipayJSOperation from '../../utils/alipayJSOperation';
import PageBar from '../../components/common/pageBar'
import BackMeanSure from '../../utils/backMeanSure';
import common from '../../utils/common';
import typeOfBrowser from '../../utils/typeOfBrowser'

import style from './sendTheAddressOfOverLine.scss'
class SendTheAddressOfOverline extends Component {
    constructor(props) {
        super(props);
        this.detailInit = this.detailInit.bind(this);
        this.backMeanSureInstance = new BackMeanSure(this.goHome.bind(this), 'sendTheAddress');
    }

    //数据初始化
    detailInit() {
        this.props.dispatch(getOrderDetail({orderId: this.props.params.orderId}));
       // this.props.dispatch(getRequirements({orderId: this.props.params.orderId}));
    }

    //返回首页
    goHome() {
        if (typeOfBrowser.getChannelOfBrowser() == 'app') {
            //app直接关闭当前webview回到年检提醒
            common.closeAppView();
        }
        else {
            history.pushState({}, '', '');
            let backNumber = -1 * history.length + 1;
            history.go(backNumber);
        }
    }


    //跳转到订单详情页
    goToDetail(back, stay, toUrl) {
        let orderDetailUrl = location.href.split('/#')[0].split('#')[0];
        if (orderDetailUrl.indexOf('?') > 0) {
            orderDetailUrl += '&OutTradeNo=' + this.props.params.orderId
        }
        else {
            orderDetailUrl += '?OutTradeNo=' + this.props.params.orderId
        }
        orderDetailUrl += '/#/orderDetails';
        toUrl(orderDetailUrl);
        /*toUrl(()=>{
         this.context.router.push('/questions');
         })*/
    }

    //构建进度条
    structProcess() {
        if (this.props.overLineOrderDetail) {
            let allLength = 4;
            let current = this.props.overLineOrderDetail.orderStatus - 1;
            let error = false;
            if (this.props.overLineOrderDetail.refundTime == 4) {
                current = 2;
                error = true;
            }
            return <HandleProcess all={allLength} current={current} error={error}/>
        }
    }

    /*

     weixinBackOperation(){
     window.history.replaceState({closeView:'overLine'},"","");
     window.history.pushState({}, "", "");
     window.history.forward();
     setTimeout(function () {
     //监听物理返回按钮
     window.addEventListener("popstate", function(e) {
     if(e.state.closeView=='overLine'){
     alert('a');
     wx.closeWindow();
     }
     })
     },300);
     }
     */

    componentDidMount() {
        this.backMeanSureInstance.bindBackMeansure();
        //this.weixinBackOperation();
        AlipayJSOperation.setRightButtonStatus(false);
        AlipayJSOperation.setTitle('年检资料及收件地址');
        //最后的页面，后退直接关闭
        AlipayJSOperation.setLeftButtonStatus(AlipayJSOperation.closeView);
        document.querySelector("title").innerHTML = "年检资料及收件地址";
        this.detailInit();
    }

    render() {
        return <div className={style.overLineContainer}>
            <PageBar title="年检资料及收件地址" isHome={true}/>
            <div className={style.overLineProcess}>
                {this.structProcess()}
                <div
                    className={style.overLineBigMsg}>{this.props.overLineOrderDetail ? this.props.overLineOrderDetail.handleMsg : ''}</div>
                <div
                    className={style.overlineSmallMsg}>{this.props.overLineOrderDetail ? this.props.overLineOrderDetail.handleRemark : ''}</div>
            </div>
            
<p style={{fontSize:'50px'}}>这个页面废弃了</p>

            <div className={style.detailContainer}>
                <div className={style.contactsGroup}>
                    <div className={style.title}>您的联系方式如下</div>
                    <div className={style.content}>
                        <div className={style.linkMan}>
                            联系人：{this.props.overLineOrderDetail ? this.props.overLineOrderDetail.name : ''}</div>
                        <div className={style.phone}>
                            联系电话：{this.props.overLineOrderDetail ? this.props.overLineOrderDetail.phone : ''}</div>
                    </div>
                    <div className={style.tips}>如需更改联系方式，请联系客服电话：020-62936789</div>
                </div>
                <div className={style.documentListGroup}>
                    <div className={style.title}>尽快整理以下年检所需资料并准备好您的待检车辆：</div>
                    <div className={style.listContent}>
                        {this.props.overLineOrderDetail ?
                            <DocumentList requirements={this.props.overLineOrderDetail.requirements}/> : ''}
                    </div>
                </div>
                <div className={style.inspectionType}>
                    <div className={style.title}>
                        车检方式：{this.props.overLineOrderDetail ? (this.props.overLineOrderDetail.driveType == '1' ? '代驾检测' : '自驾检测') : ''}</div>
                    <div
                        className={style.msg}>{this.props.overLineOrderDetail ? this.props.overLineOrderDetail.driveMsg : ''}</div>
                </div>

            </div>
        </div>
    }
}

function mapStateToProps(state) {
    return Object.assign({}, state.overLineInfo);
}

export default connect(mapStateToProps)(SendTheAddressOfOverline)